package com.ruoyi.system.api.factory;

import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.system.api.RemoteFileDataService;
import com.ruoyi.system.api.RemoteFileService;
import com.ruoyi.system.api.domain.File;
import com.ruoyi.system.api.domain.FileData;
import com.ruoyi.system.api.domain.FileObject;
import com.ruoyi.system.api.domain.SysFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;
import java.util.List;

/**
 * 文件服务降级处理
 * 
 * @author ruoyi
 */
@Component
public class RemoteFileDataFallbackFactory implements FallbackFactory<RemoteFileDataService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteFileDataFallbackFactory.class);

    @Override
    public RemoteFileDataService create(Throwable throwable)
    {
        log.error("文件服务调用失败:{}", throwable.getMessage());
        return new RemoteFileDataService()
        {
            @Override
            public R<Boolean> saveFileDataList(FileObject fileObject, String source)
            {
                return R.fail("保存文件信息失败:" + throwable.getMessage());
            }

            @Override
            public R<List<FileData>> selectFileDataList(Long groupId,String fileTypes)
            {
                return R.fail("查询文件信息失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> saveFileList(Long groupId,Integer typeId, List<Long> fileIds, String source)
            {
                return R.fail("保存文件信息失败:" + throwable.getMessage());
            }

            @Override
            public R<List<File>> selectFileList(Long groupId, String typeIds, String source)
            {
                return R.fail("查询文件信息失败:" + throwable.getMessage());
            }

            @Override
            public R<List<File>> selectFileList(File file, String source) {
                return R.fail("查询文件信息失败:" + throwable.getMessage());
            }

            @Override
            public R<File> autoUploadFileSave(File fileData, String source) {
                return R.fail("文件上传失败" + throwable.getMessage());
            }

            @Override
            public R<byte[]> fileBytes(Long fileId, String source) {
                return R.fail("下载失败" + throwable.getMessage());
            }

            @Override
            public R<List<byte[]>> fileBytesByGroup(Long fileId, String source) {
                return R.fail("获取文件失败" + throwable.getMessage());
            }

            @Override
            public R<Integer> removeFile(Long fileId, String source) {
                return R.fail("删除文件失败" + throwable.getMessage());
            }

            @Override
            public R<Integer> replaceFileList(File file, String source) {
                return R.fail("分割文件失败：" + throwable.getMessage());
            }

            @Override
            public R saveFile(File file, String source)
            {
                return R.fail("保存文件失败:" + throwable.getMessage());
            }

            @Override
            public R deleleByProcInsId(File file, String source)
            {
                return R.fail("根据流程实例删除文件失败:" + throwable.getMessage());
            }
        };
    }
}
